/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.inria.openmath.omapi;

/**
 *
 * @author Mr.Sam
 */
public class Symbol {

    // content dictionary
    private String cd;

    // and name of symbol
    private String name;


    public Symbol () {
        this("basic", "unknown");
    }

    public Symbol (String name) {
        this("basic", name);
    }

    public Symbol (String cd, String name) {
        this.cd = cd;
        this.name = name;
    }

    public String toString() {
        return cd + "." + name;
    }

    /**
     * Returns the CD of the symbol.
     *
     * @return the CD of the symbol.
     */
    public String getCD() {
        return cd;
    }

    /**
     * Returns the name of the symbol.
     *
     * @return the name of the symbol.
     */
    public String getName() {
        return name;
    }

    /**
     * Compares this Symbol to the specified object.
     *
     * <p>The result is true if and only if the argument
     * is not null and is a Symbol object that represents
     * the same symbol (same name and same CD) as this
     * object.
     * @params anObject - the object to compare this Symbol against.
     * @return true if symbols are equals, false otherwise.
     */
    public boolean equals(Object anObject) {
        return (anObject != null) && this.cd.equals(((Symbol) anObject).cd)
                && this.name.equals(((Symbol) anObject).name);
    }

    /**
     * Compares this Symbol to another (without having to build its instance).
     *
     * <p>The result is true if and only if the arguments
     * are not null and if the cdName and symbName are
     * equals to those of this object.
     * @params cdName - the cd name to compare this Symbol against.
     * @params symbName - the symbol name to compare this Symbol against.
     * @return true if symbols are equals, false otherwise.
     */
    public boolean equals(String cdName, String symbName) {
        return (cd.equals(cdName) && name.equals(symbName));
    }

    /**
     * Computes a hashcode for this symbol.
     *
     * @return A hash code.
     */
    public int hashCode() {
        return this.name.hashCode() + this.cd.hashCode();
    }

}
